/*
 * Copyright 2016-2019 yoara
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package yhao.infra.feature.dubbo;

import org.apache.dubbo.config.spring.ReferenceBean;
import org.apache.dubbo.config.spring.ServiceBean;
import org.apache.dubbo.config.spring.reference.ReferenceAttributes;
import org.springframework.context.ApplicationContext;

import java.util.LinkedHashMap;
import java.util.Map;

public class ConfigFactory {
    public static ReferenceBean makeQuickReferenceBean(String id, Class<?> interfaceClass){
        ReferenceBean bean =  new ReferenceBean();
        Map<String, Object> referenceProps = new LinkedHashMap<>();
        referenceProps.put(ReferenceAttributes.LAZY,true);
        referenceProps.put(ReferenceAttributes.INTERFACE,interfaceClass);
        referenceProps.put(ReferenceAttributes.PROTOCOL,"dubbo");
        bean.setId(id);
        return bean;
    }

    public static ServiceBean makeQuickServiceBean(ApplicationContext applicationContext,Class<?> interfaceClass, Object ref){
        ServiceBean bean =  new ServiceBean(applicationContext);
        bean.setInterface(interfaceClass);
        bean.setRef(ref);
        bean.setRetries(0);
        return bean;
    }
}
